import { FMVCS } from "../../fgui/fmvc/FMVCS";
import { GlobalEvent } from "../global/Global";
import Manager from "../../manager/Manager";
import ResultView from "./ResultView";
import { ConstDefine } from "../common/ConstDefine";
import ResultData from "./ResultData";

export default class ResultCtrl extends FMVCS.FCtrl {
    /** 数据实体 */
    static data: ResultData =  null;

    constructor(){
        super();
        ResultCtrl.data = new ResultData();
    }

    /** 事件监听注册 */
    rigisterEventListener(){
        this.on(GlobalEvent.GameEventID.GameResult, this.openView, this);
        this.on(GlobalEvent.UIListenID.UI_BtnRestart_Click, this.closeView, this);
    }

    openView(data: ConstDefine.Result.ResultEventData){
        let vo = ResultCtrl.data.vo;
        vo.isWin = data.isWin;
        vo.Level = data.level;
        vo.pattern = data.pattern;
        ResultCtrl.data.curMap = data.map;
        Manager.fui.open(ConstDefine.UI.ResultView, ResultView);
    }

    closeView(){
        Manager.fui.close(ConstDefine.UI.ResultView);
    }
}
